fix(paginate): break loop on empty items with non-null nextToken#48
Conversation
paginate() in pagination.ts entered an infinite loop when the API
returned { items: [], nextToken: 'cursor' }. The loop only checked
nextToken !== null, never whether items was empty. Any filtered list
command returning zero results would hang indefinitely.
Add an early-exit guard: if the page contains zero items, break
regardless of nextToken. Includes 5 unit tests covering the bug
reproduction, maxItems cap, single-page, and consecutive empty pages.
Closes TestSprite#35
Signed-off-by: Aldo Rizona <aldorizona10@gmail.com>
|
Hi maintainers 👋 First-time contributor here — CI runs are awaiting approval (). Quick summary of this PR:
Coverage impact: this PR adds tests to Happy to make any changes if needed. Thanks for reviewing! |
…ck gate
Pure mechanical prettier reflow of two vi.fn(async () => ({...})) callbacks in
test/pagination.test.ts. No logic change — only line wrapping to satisfy the
format:check CI gate (npm run format:check). All other gates already pass.
Coverage remains >=80% on all 4 metrics (lines/statements/functions/branches).
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Summary
Fixes an infinite loop in
paginate()(issue #35) where the CLI hangs indefinitely when a filtered list endpoint returns{ items: [], nextToken: 'cursor' }.Problem
paginate()insrc/lib/pagination.tscheckednextToken !== nullto decide whether to keep looping, but never checked whetheritemswas actually empty. Without--max-itemsset, the loop had no way to stop for this edge case, causingtestsprite test list --project <id>with a zero-result filter to hang forever.Fix
Added an early-exit guard after processing each page:
This breaks the loop when the API returns zero items, regardless of what
nextTokensays. ThenextTokenfrom the server is still returned to the caller for potential resume.Changes
src/lib/pagination.ts: Added empty-items guard inpaginate()looptest/pagination.test.ts: New file with 5 unit tests:Testing
npm run typecheck— cleannpm run lint— cleannpm run format:check— all files pass Prettiernpm test— all existing tests + 5 new tests passCloses #35
Signed-off-by: Aldo Rizona aldorizona10@gmail.com